<template>
  <div>
    <el-breadcrumb separator-class="el-icon-arrow-right" style="font-size: 16px">
      <el-breadcrumb-item :to="{ path: '/' }">后台管理</el-breadcrumb-item>
      <el-breadcrumb-item>属性模板列表</el-breadcrumb-item>
    </el-breadcrumb>



    <el-divider></el-divider>
    <el-table
        :data="tableData"
        border
        style="width: 100%">
      <el-table-column prop="id" label="ID" width="100" align="center">
      </el-table-column>
      <el-table-column prop="name" label="品牌名" width="180" align="center">
      </el-table-column>
      <el-table-column prop="pinyin" label="拼音" width="180" align="center">
      </el-table-column>
      <el-table-column prop="keywords" label="关键词" header-align="center">
      </el-table-column>
      <el-table-column prop="sort" label="排序" width="50" align="center">
      </el-table-column>
      <el-table-column label="操作" width="120" align="center">
        <template slot-scope="scope">
          <el-button type="primary" @click="handleEdit(scope.row)"
                     icon="el-icon-edit" circle size="mini"></el-button>
          <el-button type="danger" @click="openDeleteConfrim(scope.row)"
                     icon="el-icon-delete" circle size="mini"></el-button>
        </template>
      </el-table-column>
    </el-table>

  </div>
</template>



<script>
import axios from "axios";

export default {
  data() {
    return {
      tableData: [],
    }
  },
  methods:{
    handleEdit(attributeTemplate){
      let message = "您正在尝试编辑["+attributeTemplate.name+"]的详情,抱歉,该功能待完善"
      this.$alert(message, '提示', {
        confirmButtonText: '确定',
      });
    },
    handleDelete(attributeTemplate) {
      console.log('准备删除属性模板……id = '+attributeTemplate.id);
      let url = "http://127.0.0.1:9080/attributeTemplates/"+attributeTemplate.id+"/delete";
      console.log("url = "+url);
      axios.post(url).then((response)=>{
        let responseBody = response.data;
        if (responseBody.state != 20000) {
          this.$message.error(responseBody.message);
        }
        if (responseBody.state == 20000){
          this.$message({
            message: '删除成功',
            type: 'success'
          });
        }
        if (responseBody.state == 20000 || responseBody.state == 40400) {
          this.loadBrandList();
        }
      })
    },
    openDeleteConfrim(attributeTemplate) {
      this.$confirm('此操作将永久删除['+attributeTemplate.name +']属性模板, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.handleDelete(attributeTemplate);
      }).catch(() => {
      });
    },
    loadBrandList() {
      console.log("loadBrandList")
      let url = "http://127.0.0.1:9080/attributeTemplates";
      axios.get(url).then((response) => {
        let responseBody = response.data;
        this.tableData = responseBody.data;
      })
    }
  },
  mounted(){
    console.log("mounted");
    this.loadBrandList();
  }
}
</script>